function red() {
  console.log('红');
}
function green() {
  console.log('绿');
}
function yellow() {
  console.log('黄');
}

function light(timer, cb) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      cb()
      resolve()
    }, timer)
  })
}

// Promise实现
// function step() {
//   Promise.resolve().then(() => {
//     return light(3000, red)
//   }).then(() => {
//     return light(1000, green)
//   }).then(() => {
//     return light(2000, yellow)
//   }).then(() => {
//     step()
//   })
// }

//async实现
async function step() {
  await light(3000, red)
  await light(1000, green)
  await light(2000, yellow)
  step()
}
step()